<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      Array.prototype.myMap = function (cb, thisArg) {
        if (this == null) {
          throw new TypeError("this is null or not defined");
        }
        if (typeof cb != "function") {
          throw new TypeError(cb + "is not a function");
        }
        const arr = this;
        const len = arr.length;

        let k = 0;
        let res = [];
        while (k < len) {
          if (k in arr) {
            res[k] = cb(thisArg, arr[k], k, arr);
          }
          k++;
        }
        return res;
      };
    </script>
  </body>
</html>
